#!/bin/bash

#$1 filename eg. Dream\ Theater\ -\ Illumination\ Theory\ \(Audio\)-fFMDGSWhHbo.m4a
#$2 fromtime eg. 15:52
#$3 totime eg. 3:53  (aka duration from fromtime)

if test "$#" -ne "3"; then
  cat << 'EOF'
$1 filename eg. Dream\ Theater\ -\ Illumination\ Theory\ \(Audio\)-fFMDGSWhHbo.m4a
$2 fromtime eg. 15:52
$3 totime eg. 3:53  (aka duration from fromtime)
EOF
  exit 1
fi



fname="$1"
fromtime="$2"
totaltime="$3"
prefix="cut."
ext="${fname##*.}"
#extension is required so that ffmpeg can infer the format, apparently!

#echo "$ext"
suffix="_${0/*\//}_fromtime_${fromtime/:/_}_totaltime_${totaltime/:/_}_speed1p5x.${ext}"

set -x
#ffmpeg -accurate_seek -ss "$fromtime" -i "$fname" -acodec copy -aq 1 -vcodec copy -to "$totaltime" "${prefix}${fname}${suffix}"
#XXX: accurate_seek will only work when using atempo or acodec mp3 not copy!(latter not tested - only both tested!)

#this is 1.5x speed(both audio and video):
#with deintelace(seems to have no effect tho):
#ffmpeg -accurate_seek -ss "$fromtime" -i "$fname" -af atempo=1.5 -threads 4  -acodec mp3 -aq 1 -vf "setpts=0.666666666666*PTS,yadif" -to "$totaltime" "${prefix}${fname}${suffix}"
#without deinterlace:
ffmpeg -accurate_seek -ss "$fromtime" -i "$fname" -af atempo=1.5 -threads 4  -acodec mp3 -aq 1 -vf "setpts=0.666666666666*PTS" -to "$totaltime" "${prefix}${fname}${suffix}"
